<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="lib/vue.global.js"></script>
</head>
<body>
  <div id="root">
    <my-title ref="titleRef"></my-title>
    <button ref="btnRef">btn</button>
  </div>
</body>
<script type="module">
  const { createApp, reactive, ref, watchEffect, watch, onMounted } = window.Vue

  const MyTitle = {
    template: `<header>header</header>`,
    setup () {
      const title = ref('')

      onMounted(() => {
        title.value="121212"
      })

      return {
        title
      }
    }
  }
  const app = createApp({
    components: {
      MyTitle
    },
    setup(props) {
      // ref既可以用来定义简单的响应式数据
      // 也可以给模版中加ref，可以用来获取子组件的实例或者是进行DOM操作
      // react  React.createRef  React.useRef
      const btnRef = ref(null)
      const titleRef = ref(null)
      
      onMounted(() => {
        btnRef.value.style.fontSize = '30px' // 获取到DOM节点
        console.log(titleRef.value.title) // 拿到子组件的实例
      })

      return {
        btnRef,
        titleRef
      }
    }
  })

  app.mount('#root')
</script>
</html>